package com.es.servlet; /**
 * 描述:
 * es-servlet-
 *
 * @author Derek
 * 创建时间：2022-04-22 11:47
 */

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "CountOnlineMembersServlet", value = "/onlines")
public class CountOnlineMembersServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getSession();
        //
        ServletContext application = this.getServletContext();
        //
        Integer count = (Integer) application.getAttribute("count");

        //对外显示在线人数
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println("<h3>当前在线人数：");
        if(count == null){
           out.println("0 ");
        }else{
            out.println(count);
        }
        out.println("人</h3>");
        out.println("<a href='details'>查看详细</a>");
    }

}
